<template>
    <div>
        用户名：<el-input v-model="formData.username"></el-input>
        密码：<el-input type="password" v-model="formData.password"></el-input>
        <el-button @click="eventLogin">登录</el-button>
    </div>
</template>

<script>
export default {
    data() {
        return {
            formData: {
                username: '',
                password: ''
            }
        }
    },
    methods: {
        //登录事件
        eventLogin() {
            let url = this.$baseUrl + 'member/info/login'
            let data = {
                "phone": this.formData.username,
                "password": this.formData.password
            }
            this.$http.post(url, data).then(res => {


                //console.log(res);
                this.$message.info(res.data.data.msg)
                if (res.data.data.statue) {
                    //表示登录成功
                    //除了跳转之外，还需要保存用户的信息
                    let userinfo = res.data.data.data


                    /**
                     * 2023/3/13
                     * 周考3-用户登录成功后，缓存用户信息
                     */
                    //这暂时只放用户id
                    localStorage.setItem('login-userinfo', userinfo.id)

                    //将userinfo的json对象转换为字符串，并放入到内存中
                    localStorage.setItem("localstroage_userinfo", JSON.stringify(userinfo))

                    this.$router.push('/product')
                }
            })
        }
    }
}
</script>